// pages/royalty/royalty.js
const app = getApp()
const { request } = require("../../utils/request")

Page({
  data: {
    royaltyList: [],
  },

  onLoad() {
    this.fetchRoyaltyList()
  },

  // 获取提成列表
  fetchRoyaltyList() {
    wx.showLoading({
      title: "加载中",
    })

    request({
      url: `${app.globalData.baseUrl}/admin/royalty/getRoyaltyList`,
      method: "GET",
    })
      .then((res) => {
        wx.hideLoading()
        if (res.data.code === 1) {
          this.setData({
            royaltyList: res.data.data || [],
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none",
          })
        }
      })
      .catch((err) => {
        wx.hideLoading()
        console.error("请求失败:", err)
        wx.showToast({
          title: "网络请求失败",
          icon: "none",
        })
      })
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.fetchRoyaltyList()
    wx.stopPullDownRefresh()
  },
})
